package com.gtt.lazy.controller;

import java.util.List;

import com.gtt.lazy.domain.Notice;
import com.gtt.lazy.service.NoticeService;

/**
 * 公告管理Action
 * 
 * @author 高甜甜
 * @date 2009-7-9
 */
public class NoticeAction extends BaseAction {

	private static final long serialVersionUID = 1L;

	private NoticeService noticeService;

	private List<Notice> results;

	private String text;

	private int id;

	private Notice notice;

	public String list() {
		// 确定所要显示的页数
		if (page == 0)
			page = 1;
		int start = (page - 1) * Constant.SIZE;
		results = noticeService.list(start, Constant.SIZE);
		setPagination(noticeService.count(), Constant.SIZE, page);
		return SUCCESS;
	}

	public String toAdd() {
		return SUCCESS;
	}

	public String add() {
		noticeService.add(new Notice(text));
		return SUCCESS;
	}

	public String toMod() {
		notice = noticeService.get(id);
		return SUCCESS;
	}

	public String mod() {
		Notice notice = new Notice(text);
		notice.setId(id);
		noticeService.update(notice);
		return SUCCESS;
	}

	public String del() {
		noticeService.delete(id);
		return SUCCESS;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public Notice getNotice() {
		return notice;
	}

	public void setNotice(Notice notice) {
		this.notice = notice;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public List<Notice> getResults() {
		return results;
	}

	public void setResults(List<Notice> results) {
		this.results = results;
	}

	public NoticeService getNoticeService() {
		return noticeService;
	}

	public void setNoticeService(NoticeService noticeService) {
		this.noticeService = noticeService;
	}

}
